package model

import (
	"fmt"
	"jsjb/connect"
)

type AuthGroupAccess struct {
	GroupId string `json:"groupId"`
	Uid     int32  `json:"uid"`
}

func GetGroupIdByUid(uid int32) (users []AuthGroupAccess, err error) {
	if err = connect.DB.Table("auth_group_access").Where(`uid = ?`, uid).Find(&users).Error; err != nil {
		return nil, err
	}

	return
}
func (AuthGroupAccess) TableName() string {
	return "auth_group_access"
}
func BatchCreateAuthGroupAccess(aoa []AuthGroupAccess) (err error) {
	fmt.Printf("aoas%#v\n", aoa)
	results := connect.DB.Create(&aoa)
	err = results.Error
	return
}

func CreateAuthGroupAccess(aoa AuthGroupAccess) (err error) {
	results := connect.DB.Create(&aoa)
	err = results.Error
	return
}

func UpdateAuthGroupAccess(aga AuthGroupAccess) (err error) {
	results := connect.DB.Model(&aga).Where("uid = ? and group_id = ?", aga.Uid, aga.GroupId).Updates(aga)
	err = results.Error
	return
}
func BatchDeleteAuthGroupAccess(adminIds []int32) (err error) {
	results := connect.DB.Where("uid IN ?", adminIds).Delete(&AuthGroupAccess{})
	err = results.Error
	return
}
func DeleteAuthGroupAccess(uid int32) (err error) {
	results := connect.DB.Where("uid = ?", uid).Delete(&AuthGroupAccess{})
	err = results.Error
	return
}
